package com.nari.ncps.screen.service.impl.al;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nari.ncps.screen.entity.al.AlOpermonEnergyConAll;
import com.nari.ncps.screen.mapper.al.AlOpermonEnergyConAllMapper;
import com.nari.ncps.screen.service.al.AlOpermonEnergyConAllService;
import com.nari.ncps.screen.vo.al.AlOpermonEnergyConsumeAllVO;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 同步映射需要字段标准表 服务实现类
 * </p>
 *
 * @author dongxiaoxu
 * @since 2025-11-02
 */
@Service
public class AlOpermonEnergyConAllServiceImpl extends ServiceImpl<AlOpermonEnergyConAllMapper
        , AlOpermonEnergyConAll> implements AlOpermonEnergyConAllService {

    @Resource
    private AlOpermonEnergyConAllMapper alOpermonEnergyConAllMapper;


    @Override
    public AlOpermonEnergyConsumeAllVO getConsumeAll(Integer year) {

        if (year == null) {
            year = LocalDate.now().getYear();
        }

        AlOpermonEnergyConsumeAllVO vo = new AlOpermonEnergyConsumeAllVO();
        LambdaQueryWrapper<AlOpermonEnergyConAll> lqw = new LambdaQueryWrapper<>();
        lqw.eq(AlOpermonEnergyConAll::getYear, year);

        List<AlOpermonEnergyConAll> alOpermonEnergyConAlls = alOpermonEnergyConAllMapper.selectList(lqw);
        if(!alOpermonEnergyConAlls.isEmpty()) {
            AlOpermonEnergyConAll alOpermonEnergyConAll = alOpermonEnergyConAlls.get(0);

            BeanUtils.copyProperties(alOpermonEnergyConAll, vo);
        }
        return vo;
    }
}
